<?php

class User_Model_User extends Zend_Db_Table_Abstract
{

	public $_name="ha_users";
    public function __construct($config = array())
    {
        $this->_db = Zend_Db_Table::getDefaultAdapter();
        parent::__construct($config);
    }
	public function FindByUser($username){
		$sql="SELECT * FROM $this->_name WHERE USERNAME = '" . $username . "'";
		$result=$this->getDefaultAdapter()->query($sql);
		return $result->fetch();
	}
	public function  UpdateUser($params){
		$db = Zend_Db_Table::getDefaultAdapter();
		$id= $params['id'];
		$data=array(
            'USERNAME'=> $params['name'],
            'EMAIL'=>  $params['mail'],
            'SOCMND'=>  $params['socmnd'],
            'PHONE'=>  $params['phone']
		);
		try{
			
			$db->update($this->_name, $data,'ID_U = '.(int)$id);
		}catch (Exception $e){
			$e->getMessage();
			exit;
		}
	}
	public function getCompanyInfo($id){
        $sql="SELECT * FROM company WHERE id = " . $id;
		$result=$this->getDefaultAdapter()->query($sql);
		return $result->fetch();
    }
	public function  UpdatePass($params){
		$db = Zend_Db_Table::getDefaultAdapter();
		$id= $params['id'];
		$data=array('PASSWORD'=> md5($params['newpass']));
		try{
			$db->update($this->_name, $data,'ID_U = '.(int)$id);
		}catch (Exception $e){
			$e->getMessage();
			exit;
		}
	}
}